package thread;

import java.util.Scanner;

public class Demo9 {
    private static boolean running = true;

    public static void main(String[] args) {
        //boolean running = true;
        Thread t = new Thread(() -> {
            while (running) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("thread 结束");
        });

        t.start();

        Scanner scanner = new Scanner(System.in);
        System.out.println("输入任意内容, 控制 t 线程结束: ");
        scanner.next();
        running = false;
    }
}
